package com.rules.admin.controller;

import com.rules.admin.utils.ResultUtils;
import com.rules.admin.entity.TestLogModel;
import com.rules.admin.service.TestLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping({"/test-log"})
public class TestLogController {
   @Autowired
   private TestLogService testLogService;

   @RequestMapping(
      value = {"/rule/{id}"},
      method = {RequestMethod.GET}
   )
   @ResponseBody
   public Map<String, Object> getDeductionNos(@PathVariable("id") Long ruleId, String testId) {
      List<TestLogModel> testLogModels = this.testLogService.getDeductionNos(ruleId, testId);
      List<Integer> result = new ArrayList();
      Iterator var5 = testLogModels.iterator();

      while(var5.hasNext()) {
         TestLogModel testLogModel = (TestLogModel)var5.next();
         result.add(testLogModel.getDeductionno());
      }

      return ResultUtils.getSuccessResultData(result);
   }

   @RequestMapping(
      value = {"/package"},
      method = {RequestMethod.GET}
   )
   @ResponseBody
   public Map<String, Object> getLogByPackage(String testId) {
      List<TestLogModel> testLogModels = this.testLogService.getByTestId(testId);
      List<String> result = new ArrayList();
      Iterator var4 = testLogModels.iterator();

      while(var4.hasNext()) {
         TestLogModel testLogModel = (TestLogModel)var4.next();
         if (!result.contains(testLogModel.getRuleid().toString())) {
            result.add(testLogModel.getRuleid().toString());
         }
      }

      return ResultUtils.getSuccessResultData(result);
   }
}
